home *** CD-ROM | disk | FTP | other *** search
/ Dr. Windows 3 / dr win3.zip / dr win3 / VISUALBA / SCROLVB.ZIP / SCROLL-1.TXT < prev    next >
Text File  |  1994-02-01  |  8KB  |  171 lines

  1.  
  2. > Program: SCROLL-1 - Visual Basic Demo Code
  3.  
  4. > Written By: Paul T. Dawson, P.O. Box 682, Chincoteague, VA, 23336
  5.  
  6. > Summary: VB 2.0 or 3.0 sample code that demonstrates "form scrolling".
  7.   No VBX controls required. No API calls required. No cost (free!).
  8.  
  9. > Requirements: To run the SCROLL-1.EXE file - Windows 3.x and VBRUN200.DLL.
  10.   To use the sample code - Visual Basic 2.0 or higher.
  11.  
  12. > Design Goals:
  13.  
  14.   1. Make a resizable form, with scroll bars to move around a large area.
  15.   2. Use the minimum amount of code.
  16.   3. Use default values wherever possible.
  17.   4. Add lots of comments!
  18.  
  19. > File List:
  20.  
  21.   SCROLL-1.TXT - This File (no margins or page breaks).
  22.   SCROLL-1.MAK - Visual Basic Project.
  23.   SCROLL-1.FRM - Visual Basic Form.
  24.   SCROLL-1.FRX - Visual Basic Graphics (just one little icon).
  25.   SCROLL-1.EXE - Finished EXE file.
  26.  
  27. > Design Summary:
  28.  
  29.   This program uses one standard resizable form, and a "scrolling" picture
  30.   box for the "container" for all of the controls. There are two scroll bars
  31.   on the form that let the user scroll around the picture box. The program
  32.   moves the scroll bars to their new locations every time the main form is
  33.   resized. Then the user can scroll anywhere in the picture box.
  34.  
  35.   The scrolling picture box can be many times larger than the screen, and
  36.   any control can be placed anywhere on it.
  37.  
  38. > Details About Objects:
  39.  
  40.   1. frmMain:
  41.      The main form has a ScaleMode of 3 (pixel).
  42.      Everything else on the form is default.
  43.  
  44.   2. hsb1 / vsb1:
  45.      The two scroll bars are in temporary locations on the form.
  46.      They will be automatically moved to the edges when you click cmdStart.
  47.      The values of SmallChange and LargeChange are 10 and 50. These values
  48.      are not critical, and they can be changed. Everything else is default.
  49.  
  50.   3. picCorner:
  51.      This is the little grey box that goes into the lower right corner.
  52.      The BorderStyle is 1, and the BackColor is light grey. You can change
  53.      the BackColor to something else, if you want to see exactly where
  54.      picCorner lands!
  55.  
  56.   4. picBig:
  57.      This is the big scrolling picture box. In this demo, it starts out
  58.      relatively small. Then cmdStart resizes it to be larger than the form.
  59.  
  60.      The picBig AutoRedraw property is set to False, which is the default.
  61.      If you set the picBig AutoRedraw to True, then it will be easier to
  62.      print and draw graphics directly on picBig. However, AutoRedraw=True
  63.      uses a LOT of memory, so it's best to leave it False!
  64.  
  65.      With AutoRedraw=False, I have successfully tested this up to 16,383 by
  66.      16,383 pixels, the equivalent of 873 standard VGA screens. Above that
  67.      number, which is (2^14)-1, things start to get flakey. The picture box
  68.      will not display properly, most likely because of some internal VB
  69.      restriction! On my machine, VB says 16,383 pixels is 170 inches, or just
  70.      over 14 feet. So you can have a scrolling picture box that covers 200
  71.      actual square feet. That should be sufficient!
  72.  
  73.      The picBig ScaleMode is set to 3 (pixel) - this is important for this
  74.      demo program, and it's just a lot more convenient than "Twips". You can
  75.      always use Twips in other programs, if you really want to!
  76.  
  77.      After putting the scroll bars and the picture boxes on the form, it's
  78.      important to select the picBig box and hit "Edit - Send to Back", so it
  79.      won't ever cover the scroll bars or the picCorner box.
  80.  
  81.      The picBig BackColor is cyan - this isn't critical.
  82.  
  83.   5. lblDownLeft / lblDownRight / lblUpLeft / lblUpRight:
  84.      The four labels on the picBig control are just samples, to show how all
  85.      controls in a "container" keep the same location in the container, even
  86.      if the container moves around, or part of it is hidden.
  87.  
  88.   6. cmdStart:
  89.      When you click this, everything starts to happen! This button was added
  90.      for the convenience of people without VB who just want to try the EXE
  91.      file. It just makes things more interesting to see all of the controls
  92.      before they are resized.
  93.  
  94.   7. cmdExit(0 to 7):
  95.      These are some extra non-critical controls that I added to picBig, to
  96.      make the scrolling more visible. For a "real" program, these would all
  97.      be replaced with "real" controls that actually did something. Actually,
  98.      in this program, all of these buttons do something - end the program!
  99.  
  100. > Miscellaneous Notes:
  101.  
  102.   1. The horizontal scroll bar can be any height, and the vertical one can
  103.      be any width. Try changing these, and you'll see that the code adjusts
  104.      EVERYTHING to match!
  105.  
  106.   2. Remember, any type of control can be placed onto the picBig control!!!
  107.  
  108.   3. In writing this program, I found that the first EASY part was getting
  109.      the scroll bars to jump to the edges after every form resize. The second
  110.      EASY part was using the scroll bars to move the big picture box around.
  111.      The completely unexpected HARD part was taking care of problems when
  112.      just one scroll bar is visible!?!
  113.  
  114.      It's easy to place things when both scroll bars are either visible or
  115.      invisible. However, when just one is visible, things get complicated!
  116.  
  117.      For example, if the entire width of picBig is visible, then the
  118.      horizontal scroll bar can be turned off. Well, when you remove that from
  119.      the bottom of the form, right away you have to check if the entire
  120.      height of picBig is visible!
  121.  
  122.      The opposite is when the entire height is visible - then you turn off
  123.      the vertical scroll bar, and you have to check if that makes the entire
  124.      width of picBig visible!
  125.  
  126.      In either case, you have to erase the picCorner box, and then adjust the
  127.      scroll bar again to fill in that space - whew!
  128.  
  129.      The solution that I finally used was to set up three flags, for the one
  130.      corner box and the two scroll bars. The Form_Resize event will call the
  131.      FixScrollBars sub, where these flags are all set to False, and then with
  132.      some repetitive lines (all 16 of them), none/some/all of these flags are
  133.      set to True.
  134.  
  135.      Then all three controls are put in the right places, and turned on or
  136.      off depending on what the flags say!
  137.  
  138.      This system will always work properly. While testing this program, I put
  139.      a loop around those lines, so instead of checking once, it checked 1000
  140.      times. The total time required was 18 seconds, or .018 second for just
  141.      one "normal" check. That's fast enough (tested on a slow 386 even)!
  142.  
  143.   4. In the FixScrollBars sub, there are several "+1" and "+2" variations in
  144.      the sizes of the scroll bars. These are necessary to make everything
  145.      line up perfectly. I used "ZoomIn" to look closely at each combination,
  146.      and make sure everything was exact!
  147.  
  148.   5. For VB beginners, here's how to put new controls INTO a container:
  149.  
  150.      First, select the container (usually a picture box or frame). Then,
  151.      while it is selected, move over to the toolbox and click on the control
  152.      you want. Move the mouse pointer back over the container, and THEN hold
  153.      down the button, drag, and release. The new control should be inside the
  154.      container now. To make sure, select it and try to drag it off the
  155.      container. If you can't, then the operation was successful!
  156.  
  157.      Having a control IN a container is completely different than having a
  158.      control ON TOP of a container. If you create a control and then drag it
  159.      on top of a picture box, it will NOT be "in" that container. If you move
  160.      the picture box, the control will NOT move with it!
  161.  
  162.      To move an existing control INTO a container, here's what to do: Select
  163.      the control, and hit "ALT E" and "T". This will cut the control, which
  164.      means it will disappear from the form. Then select the container, and
  165.      while it is selected, hit "CTRL V" and the control will be pasted into
  166.      the container.
  167.  
  168.   6. Please experiment on non-critical projects first!
  169.  
  170. /**** <End Of This File> - <10-29-93> - <P.T.D.> ****/
  171.